// component/cardLow/cardLow.js
var configUrl = require('../../../config/config')  //引入配置接口文件
const app=getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    data:{
      type: Object,
      // 数据类型
      value:{}
      // 数据值
    }
  },
  options: {
    styleIsolation: 'apply-shared'
  },
  /**
   * 组件的初始数据
   */
  data: {
    imgUrl:getApp().globalData.imgUrl,
    hotSelect: 0,
    titleData: [],
    contentData: [],
    picChamfer: "Y",
    textAlign: "left",
    textStyle: "normal"
  },
  attached: function(){
    let cardDTOList = this.properties.data.cardDTOList
    console.log('哈哈哈测试',cardDTOList)
    let titleData = [] // 标题数据
    let contentData = [] // 内容数据
    for (var i = 0; i< cardDTOList.length; i++) {
      // 标题数据整理
      let objTitle = {}
      if (cardDTOList[i].titleType == 'text') {
        objTitle.id = cardDTOList[i].id
        objTitle.subTitleSelectedBgColor = cardDTOList[i].subTitleSelectedBgColor
        objTitle.subTitleSelectedTextColor = cardDTOList[i].subTitleSelectedTextColor
        objTitle.subTitleText = cardDTOList[i].subTitleText
        objTitle.subTitleTextColor = cardDTOList[i].subTitleTextColor
        objTitle.titlePic = cardDTOList[i].titlePic
        objTitle.titleSelectedBgColor = cardDTOList[i].titleSelectedBgColor
        objTitle.titleSelectedPic = cardDTOList[i].titleSelectedPic
        objTitle.titleSelectedTextColor = cardDTOList[i].titleSelectedTextColor
        objTitle.titleText = cardDTOList[i].titleText
        objTitle.titleTextColor = cardDTOList[i].titleTextColor
        objTitle.titleType = cardDTOList[i].titleType
      }
      if (cardDTOList[i].titleType == 'picture') {
        objTitle.id = cardDTOList[i].id
        objTitle.titlePic = cardDTOList[i].titlePic
        objTitle.titleSelectedPic = cardDTOList[i].titleSelectedPic
        objTitle.titleType = cardDTOList[i].titleType
      }
      titleData.push(objTitle)
      this.setData({
        titleData: titleData,
        hotSelect: titleData[0].id
      })

      // 内容数据结构调整  一行两个
      if (cardDTOList[i].layoutStyle == "oneLineTwo") {
        // 整体
        if (cardDTOList[i].layoutType == "whole") {
          let wholeObj = {}
          wholeObj.layoutStyle = cardDTOList[i].layoutStyle
          wholeObj.layoutType = cardDTOList[i].layoutType
          wholeObj.lineFeedFlag = cardDTOList[i].lineFeedFlag
          wholeObj.id = cardDTOList[i].id
          wholeObj.showMoreButton = cardDTOList[i].showMoreButton
          wholeObj.moreButtonTextColor = cardDTOList[i].moreButtonTextColor
          wholeObj.moreButtonFrameColor = cardDTOList[i].moreButtonFrameColor
          wholeObj.moreButtonLinkAppId = cardDTOList[i].moreButtonLinkAppId
          wholeObj.moreButtonLinkType = cardDTOList[i].moreButtonLinkType
          wholeObj.moreButtonLinkUrl = cardDTOList[i].moreButtonLinkUrl
          wholeObj.moreButtonResourceId = cardDTOList[i].moreButtonResourceId
          // 商品专栏
          if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'specialColumn') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.solrProductDtos.records
            // 秒杀，拼团，砍价
          } else if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'seckill') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.products
          } else if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'spellBuy') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.buySkuList
          } else if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'cutPrice') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.priceSkuList
          } else if(!cardDTOList[i].cardItemGroupDTOList[0].contentType) {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].cardItemDTOList
          }
          // wholeObj.topData = wholeObj.cardData.slice(0, 1)
          // wholeObj.cardData = wholeObj.cardData.slice(1, 4)
          wholeObj.linkType = cardDTOList[i].cardItemGroupDTOList[0].linkType
          wholeObj.linkUrl = cardDTOList[i].cardItemGroupDTOList[0].linkUrl
          wholeObj.linkAppId = cardDTOList[i].cardItemGroupDTOList[0].linkAppId
          wholeObj.linkResourceId = cardDTOList[i].cardItemGroupDTOList[0].linkResourceId
          wholeObj.contentType = cardDTOList[i].cardItemGroupDTOList[0].contentType
          contentData.push(wholeObj)
        }
        // 独立
        if (cardDTOList[i].layoutType == "independent") {
          let cardItemGroupDTOList = cardDTOList[i].cardItemGroupDTOList
          let independentObj = {}
          let independentData = []
          independentObj.layoutStyle = cardDTOList[i].layoutStyle
          independentObj.layoutType = cardDTOList[i].layoutType
          independentObj.lineFeedFlag = cardDTOList[i].lineFeedFlag
          independentObj.id = cardDTOList[i].id
          independentObj.showMoreButton = cardDTOList[i].showMoreButton
          independentObj.moreButtonTextColor = cardDTOList[i].moreButtonTextColor
          independentObj.moreButtonFrameColor = cardDTOList[i].moreButtonFrameColor
          independentObj.moreButtonLinkAppId = cardDTOList[i].moreButtonLinkAppId
          independentObj.moreButtonLinkType = cardDTOList[i].moreButtonLinkType
          independentObj.moreButtonLinkUrl = cardDTOList[i].moreButtonLinkUrl
          independentObj.moreButtonResourceId = cardDTOList[i].moreButtonResourceId
          for (var k = 0; k < cardItemGroupDTOList.length; k++) {
            let newIndepObj = {}
            newIndepObj = cardItemGroupDTOList[k].cardItemDTOList[0]
            newIndepObj.linkType = cardItemGroupDTOList[k].linkType
            newIndepObj.linkUrl = cardItemGroupDTOList[k].linkUrl
            newIndepObj.linkAppId =  cardItemGroupDTOList[k].linkAppId
            newIndepObj.linkResourceId =  cardItemGroupDTOList[k].linkResourceId
            newIndepObj.contentType = cardItemGroupDTOList[k].contentType
            independentData.push(newIndepObj)
            independentObj.cardData = independentData
            // independentObj.topData = independentObj.cardData.slice(0, 1)
            // independentObj.cardData = independentObj.cardData.slice(1, 4)
          }
          contentData.push(independentObj)
        }
         // 一行三个
      } else if (cardDTOList[i].layoutStyle == "oneLineThree") {
        // 整体
        if (cardDTOList[i].layoutType == "whole") {
          let wholeObj = {}
          wholeObj.layoutStyle = cardDTOList[i].layoutStyle
          wholeObj.layoutType = cardDTOList[i].layoutType
          wholeObj.id = cardDTOList[i].id
          wholeObj.showMoreButton = cardDTOList[i].showMoreButton
          wholeObj.moreButtonTextColor = cardDTOList[i].moreButtonTextColor
          wholeObj.moreButtonFrameColor = cardDTOList[i].moreButtonFrameColor
          wholeObj.moreButtonLinkAppId = cardDTOList[i].moreButtonLinkAppId
          wholeObj.moreButtonLinkType = cardDTOList[i].moreButtonLinkType
          wholeObj.moreButtonLinkUrl = cardDTOList[i].moreButtonLinkUrl
          wholeObj.moreButtonResourceId = cardDTOList[i].moreButtonResourceId
          // 商品专栏
          if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'specialColumn') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.solrProductDtos.records
            // 秒杀，拼团，砍价
          } else if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'seckill') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.products
          } else if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'spellBuy') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.buySkuList
          } else if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'cutPrice') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.priceSkuList
          } else if(!cardDTOList[i].cardItemGroupDTOList[0].contentType) {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].cardItemDTOList
          }
          // wholeObj.topData = wholeObj.cardData.slice(0, 1)
          // wholeObj.cardData = wholeObj.cardData.slice(1, 4)
          wholeObj.linkType = cardDTOList[i].cardItemGroupDTOList[0].linkType
          wholeObj.linkUrl = cardDTOList[i].cardItemGroupDTOList[0].linkUrl
          wholeObj.linkAppId = cardDTOList[i].cardItemGroupDTOList[0].linkAppId
          wholeObj.linkResourceId = cardDTOList[i].cardItemGroupDTOList[0].linkResourceId
          wholeObj.contentType = cardDTOList[i].cardItemGroupDTOList[0].contentType
          contentData.push(wholeObj)
        }
        // 独立
        if (cardDTOList[i].layoutType == "independent") {
          let cardItemGroupDTOList = cardDTOList[i].cardItemGroupDTOList
          let independentObj = {}
          let independentData = []
          independentObj.layoutStyle = cardDTOList[i].layoutStyle
          independentObj.layoutType = cardDTOList[i].layoutType
          independentObj.id = cardDTOList[i].id
          independentObj.showMoreButton = cardDTOList[i].showMoreButton
          independentObj.moreButtonTextColor = cardDTOList[i].moreButtonTextColor
          independentObj.moreButtonFrameColor = cardDTOList[i].moreButtonFrameColor
          independentObj.moreButtonLinkAppId = cardDTOList[i].moreButtonLinkAppId
          independentObj.moreButtonLinkType = cardDTOList[i].moreButtonLinkType
          independentObj.moreButtonLinkUrl = cardDTOList[i].moreButtonLinkUrl
          independentObj.moreButtonResourceId = cardDTOList[i].moreButtonResourceId
          for (var k = 0; k < cardItemGroupDTOList.length; k++) {
            let newIndepObj = {}
            newIndepObj = cardItemGroupDTOList[k].cardItemDTOList[0]
            newIndepObj.linkType = cardItemGroupDTOList[k].linkType
            newIndepObj.linkUrl = cardItemGroupDTOList[k].linkUrl
            newIndepObj.linkAppId = cardItemGroupDTOList[k].linkAppId
            newIndepObj.linkResourceId = cardItemGroupDTOList[k].linkResourceId
            newIndepObj.contentType = cardItemGroupDTOList[k].contentType
            independentData.push(newIndepObj)
            independentObj.cardData = independentData
            // independentObj.topData = independentObj.cardData.slice(0, 1)
            // independentObj.cardData = independentObj.cardData.slice(1, 4)
          }
          contentData.push(independentObj)
        }
         // 大图
      } else if (cardDTOList[i].layoutStyle == "bigOne") {
        // 整体
        if (cardDTOList[i].layoutType == "whole") {
          let wholeObj = {}
          wholeObj.layoutStyle = cardDTOList[i].layoutStyle
          wholeObj.layoutType = cardDTOList[i].layoutType
          wholeObj.id = cardDTOList[i].id
          wholeObj.showMoreButton = cardDTOList[i].showMoreButton
          wholeObj.moreButtonTextColor = cardDTOList[i].moreButtonTextColor
          wholeObj.moreButtonFrameColor = cardDTOList[i].moreButtonFrameColor
          wholeObj.moreButtonLinkAppId = cardDTOList[i].moreButtonLinkAppId
          wholeObj.moreButtonLinkType = cardDTOList[i].moreButtonLinkType
          wholeObj.moreButtonLinkUrl = cardDTOList[i].moreButtonLinkUrl
          wholeObj.moreButtonResourceId = cardDTOList[i].moreButtonResourceId
          // 商品专栏
          if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'specialColumn') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.solrProductDtos.records
            // 秒杀，拼团，砍价
          } else if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'seckill') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.products
          } else if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'spellBuy') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.buySkuList
          } else if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'cutPrice') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData.priceSkuList
          } else if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'selectedCase') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData
          } else if (cardDTOList[i].cardItemGroupDTOList[0].contentType == 'articleType') {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].contentData
          } else if(!cardDTOList[i].cardItemGroupDTOList[0].contentType) {
            wholeObj.cardData = cardDTOList[i].cardItemGroupDTOList[0].cardItemDTOList
          }
          // wholeObj.topData = wholeObj.cardData.slice(0, 1)
          // wholeObj.cardData = wholeObj.cardData.slice(1, 4)
          wholeObj.linkType = cardDTOList[i].cardItemGroupDTOList[0].linkType
          wholeObj.linkUrl = cardDTOList[i].cardItemGroupDTOList[0].linkUrl
          wholeObj.linkAppId = cardDTOList[i].cardItemGroupDTOList[0].linkAppId
          wholeObj.linkResourceId = cardDTOList[i].cardItemGroupDTOList[0].linkResourceId
          wholeObj.contentType = cardDTOList[i].cardItemGroupDTOList[0].contentType
          contentData.push(wholeObj)
        }
        // 独立
        if (cardDTOList[i].layoutType == "independent") {
          let cardItemGroupDTOList = cardDTOList[i].cardItemGroupDTOList
          let independentObj = {}
          let independentData = []
          independentObj.layoutStyle = cardDTOList[i].layoutStyle
          independentObj.layoutType = cardDTOList[i].layoutType
          independentObj.id = cardDTOList[i].id
          independentObj.showMoreButton = cardDTOList[i].showMoreButton
          independentObj.moreButtonTextColor = cardDTOList[i].moreButtonTextColor
          independentObj.moreButtonFrameColor = cardDTOList[i].moreButtonFrameColor
          independentObj.moreButtonLinkAppId = cardDTOList[i].moreButtonLinkAppId
          independentObj.moreButtonLinkType = cardDTOList[i].moreButtonLinkType
          independentObj.moreButtonLinkUrl = cardDTOList[i].moreButtonLinkUrl
          independentObj.moreButtonResourceId = cardDTOList[i].moreButtonResourceId
          for (var k = 0; k < cardItemGroupDTOList.length; k++) {
            let newIndepObj = {}
            newIndepObj = cardItemGroupDTOList[k].cardItemDTOList[0]
            newIndepObj.linkType = cardItemGroupDTOList[k].linkType
            newIndepObj.linkUrl = cardItemGroupDTOList[k].linkUrl
            newIndepObj.linkAppId = cardItemGroupDTOList[k].linkAppId
            newIndepObj.linkResourceId = cardItemGroupDTOList[k].linkResourceId
            newIndepObj.contentType = cardItemGroupDTOList[k].contentType
            independentData.push(newIndepObj)
            independentObj.cardData = independentData
            // independentObj.topData = independentObj.cardData.slice(0, 1)
            // independentObj.cardData = independentObj.cardData.slice(1, 4)
          }
          contentData.push(independentObj)
        }
      }
      this.setData({
        contentData: contentData
      })
      console.log('内容管理页面配置',contentData)
    }
    // console.log('卡片-矮数据', this.data.contentData)
  },
  ready: function() {
    this.setData({
      picChamfer: this.properties.data.picChamfer,
      textAlign: this.properties.data.textAlign,
      textStyle: this.properties.data.textStyle
    })
  },
  /**
   * 组件的方法列表
   */
  methods: {
    tabHot(data) {
      const id = data.currentTarget.dataset.data.id
      this.setData({
        hotSelect: id
      })
    },
    // 页面跳转
    linkJump(listItem) {
      if(typeof listItem.currentTarget.dataset.listitem=='string'){
        this.goMeita(listItem.currentTarget.dataset.listitem)
      }else{
        wx.navigateTo({
          url: listItem.currentTarget.dataset.listitem.linkUrl
        })
      }
      return
      console.log('跳转详情页',listItem.currentTarget.dataset.listitem)
      let linkType = listItem.currentTarget.dataset.listitem.linkType
      let linkAppId =  listItem.currentTarget.dataset.listitem.linkAppId
      // let linkResourceId = listItem.currentTarget.dataset.listitem.linkResourceId
      let linkUrl = listItem.currentTarget.dataset.listitem.linkUrl
      let contentType = listItem.currentTarget.dataset.listitem.contentType
      console.log('详情页',linkUrl)
      if(linkUrl){
        wx.navigateTo({
          url: linkUrl
        })
        return
      }
      if (linkType == 'otherMiniProgram') { // 其他小程序跳转
        this.goMeita(linkAppId)
      } else if (linkType == 'miniPage') {
        wx.navigateTo({
          url: linkUrl
        })
      } else if(linkType == 'h5' && linkUrl!== '/packagBuy/pages/found/crmweb/index') {
        wx.navigateTo({
          url: '/packagBuy/pages/marketing/poster/posterh5/posterh5?h5Url=' + linkUrl
        })
      } else if(linkUrl == '/packagBuy/pages/found/crmweb/index') {
        wx.navigateTo({
          url: '/packagBuy/pages/found/crmweb/index'
        })
      } else {
       if (contentType == 'selectedCase') {
        this.goMeita(linkAppId)
       } else if(contentType == 'articleType') {
        console.log('家居百科/友家秀详情id',this.data.hotSelect)
        if(this.data.hotSelect=='426'||this.data.hotSelect=='1083'){//家居百科
          wx.navigateTo({
          url: '/packagBuy/pages/found/encyclopedia/encyclopedia'
        })
        }else if(this.data.hotSelect=='427'||this.data.hotSelect=='1084'){//友家秀
          wx.navigateTo({
            url:  "/packagBuy/pages/found/show/show"
          })
        }
       }
      }
    },
    goSeeMore(listItem) {
      console.log('测试友家秀', listItem)
      let linkType = listItem.currentTarget.dataset.listitem.moreButtonLinkType
      let linkAppId =  listItem.currentTarget.dataset.listitem.moreButtonLinkAppId
      // let linkResourceId = listItem.currentTarget.dataset.listitem.linkResourceId
      let linkUrl = listItem.currentTarget.dataset.listitem.moreButtonLinkUrl
      let contentType = listItem.currentTarget.dataset.listitem.contentType
      if (linkType == 'otherMiniProgram') { // 其他小程序跳转
        this.goMeita(linkAppId)
      } else if (linkType == 'miniPage') {
        console.log('小程序跳转1')
        wx.navigateTo({
          url: linkUrl
        })
      } else if(linkType == 'h5' && linkUrl!== '/packagBuy/pages/found/crmweb/index') {
        wx.navigateTo({
          url: '/packagBuy/pages/marketing/poster/posterh5/posterh5?h5Url=' + linkUrl
        })
      } else if(linkUrl == '/packagBuy/pages/found/crmweb/index') {
        wx.navigateTo({
          url: '/packagBuy/pages/found/crmweb/index'
        })
      } else {
       if (contentType == 'selectedCase') {
        this.goMeita(linkAppId)
       } else if(contentType == 'articleType') {
        console.log('家居百科/友家秀id',this.data.hotSelect)
        if(this.data.hotSelect==='426'||this.data.hotSelect=='1083'){//家居百科
          wx.navigateTo({
          url: '/packagBuy/pages/found/encyclopedia/encyclopedia'
        })
        }else if(this.data.hotSelect==='427'||this.data.hotSelect=='1084'){//友家秀
          wx.navigateTo({
            url:  "/packagBuy/pages/found/show/show"
          })
        }
        
       }
      }
    },
    // 美搭小程序跳转
  goMeita(linkAppId) {
    wx.navigateToMiniProgram({
      appId: linkAppId,//小程序appid
      path: '',//跳转关联小程序app.json配置里面的地址
      extraData: {
        foo: 'bar'
      },
     //**重点**要打开的小程序版本，有效值 develop（开发版），trial（体验版），release（正式版）
      envVersion: 'release',
      success(res) {
        // 打开成功
      }
    })
  },
    // tabFound(data) {
    //   const id = data.currentTarget.dataset.data.id
    //   this.setData({
    //     foundSelect: id
    //   })
    // },
    // getRecommendList() {
    //   let that = this
    //   app.reqFun.requestJson('GET',configUrl.foundApi.getRecommendList,'',(res)=>{
    //     if(res.data.success==1){
    //       this.setData({
    //         recommendList: res.data.data
    //       })
    //       console.log('recommendList', that.data.recommendList)
    //     }
    //   })
    // },
  }
})
